package edu.neelsys.mvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import edu.neelsys.business.userauth.UserService;
import edu.neelsys.objectmodel.dbentites.User;

@Controller
@RequestMapping("/register")
public class RegistrationController {

	@Autowired
	private UserService userService;

	@RequestMapping(method = RequestMethod.GET)
	public String setUp(Model model) {

		return "register";
	}

	@RequestMapping(value = "/{save}", headers = "Accept=*/*", method = RequestMethod.POST)
	protected ModelAndView onSubmit(@ModelAttribute("user") User user)
			throws Exception {

		userService.createUser(user);

		return new ModelAndView("success", "user", user);

	}
}
